package com.itheima.pinda.authority.biz.service.common.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.authority.biz.dao.common.LoginLogMapper;
import com.itheima.pinda.authority.biz.service.common.MyLoginLogService;
import com.itheima.pinda.authority.entity.common.LoginLog;
import com.itheima.pinda.dozer.DozerUtils;
import com.itheima.pinda.log.entity.LoginLogDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author llhuang10
 * @date 2021/8/27 17:11
 */
@Slf4j
@Service
public class MyLoginLogServiceImpl extends ServiceImpl<LoginLogMapper, LoginLog> implements MyLoginLogService {

    @Resource
    private DozerUtils dozerUtils;

    // @Resource
    // private UserService userService;

    /**
     * 保存用户的登录日志
     *
     * @param loginLogDTO 登录日志
     */
    @Override
    public void save(LoginLogDTO loginLogDTO) {

        // 2021年8月28日09:56:35, 由于修改了切面逻辑, 获取了登录的所有信息, 所以这里不需要查一次DB了
        // // 根据账号查询user信息
        // User user = userService
        //         .getOne(Wrappers.<User>lambdaQuery().eq(User::getAccount, loginLogDTO.getAccount()));
        // // 将user信息填充到 loginLogDTO
        // loginLogDTO.setUserId(user.getId())
        //         .setUserName(user.getName());

        baseMapper.insert(dozerUtils.map(loginLogDTO, LoginLog.class));
    }
}
